package com.hhh.petadopt.serviceImpl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import com.hhh.petadopt.mapper.AdminMapper;
import com.hhh.petadopt.pojo.Admin;
import com.hhh.petadopt.service.adminService;
/**
 * 管理管理员
 * @author 杜镇声声
 *
 */
@Service
public class adminServiceImpl implements adminService {
	
	@Autowired
	private AdminMapper adminmapper;

	//查询所有管理员
	@Override
	public List<Admin> adminLists() {
		List<Admin> adminList = adminmapper.adminList();
		return adminList;
	}

	//管理员信息回显
	@Override
	public Admin selectAdminById(Integer id) {
		Admin adminInfo = adminmapper.selectAdminByid(id);
		//将管理员密码转换成*****代替
		adminInfo.setAdminpassword("****");
		return adminInfo;
	}

	//修改管理员信息
	@Override
	public void updateAdminByIds(Admin ad) {
		adminmapper.updateAdminByid(ad);
		
	}
//添加管理员
	@Override
	public void addAdmins(Admin admin) {
		//将用管理员密码进行md5加密
		String password = DigestUtils.md5DigestAsHex(admin.getAdminpassword().getBytes());
		admin.setAdminpassword(password);
		adminmapper.addAdmin(admin);
		
	}

	//删除管理员
	@Override
	public void deleteAdmin(Integer id) {
		adminmapper.deleteAdminById(id);
		
	}

	//批量删除管理员
	@Override
	public void deleteAdminsByIds(Integer[] ids) {
		adminmapper.deleteAdminsByIds(ids);
		
	}

	//搜索
	@Override
	public List<Admin> searchAdminByWord(String word) {
		List<Admin> adminList = adminmapper.searchAdminByWord(word);
		return adminList;
	}

}
